#pragma once

#include <opencv2/opencv.hpp> 
using namespace cv;


void drawing_geometry_demo(Mat& image)
{
	Mat bg = Mat::zeros(image.size(), image.type());
	Mat dst;

	Rect rect;
	rect.x = 100;
	rect.y = 100;

	rect.width = 1000;
	rect.height = 1000;
	//矩形绘制
	rectangle(bg, rect, Scalar(0, 0, 255), 2, LINE_8, 0);
	//园绘制
	circle(bg, Point(350, 400), 50, Scalar(255, 0, 255), -1, LINE_8, 0);
	//线绘制
	line(bg, Point(100, 100), Point(350, 400), Scalar(200, 255, 0), 2, LINE_AA, 0);
	//椭圆绘制
	RotatedRect rrt;
	rrt.center = Point(200, 200);
	rrt.size = Size(100, 140);
	rrt.angle = 45;
	ellipse(image, rrt, Scalar(200, 255, 0), 2, LINE_AA);


	addWeighted(image, 0.7, bg, 0.3, 0, dst);
	imshow("draw", image);
}


void random_demo()
{
	Mat canvas = Mat::zeros(Size(512, 512), CV_8UC3);

	int height = canvas.rows;
	int width = canvas.cols;

	RNG rng(12345);

	while (true)
	{
		int c = waitKeyEx(10);
		if (c == 27) { break; }
		int x1 = rng.uniform(0, width);
		int y1 = rng.uniform(0, height);
		int x2 = rng.uniform(0, width);
		int y2 = rng.uniform(0, height);
		int pr = rng.uniform(0, 255);
		int pg = rng.uniform(0, 255);
		int pb = rng.uniform(0, 255);
		int lineThickness = rng.uniform(1, 8);
		canvas = Scalar(0, 0, 0);
		line(canvas, Point(x1, y1), Point(x2, y2), Scalar(pb, pg, pr), lineThickness, LINE_AA, 0);
		imshow("random draw", canvas);

	}
}

void polyline_drawing_demo()
{
	Mat canvas = Mat::zeros(Size(512, 512), CV_8UC3);
	Point p1(100, 100);
	Point p2(350, 150);
	Point p3(500, 200);
	Point p4(380, 450);
	Point p5(80, 200);

	//创建多边形的点
	std::vector<Point> pts;
	//将每个点压入vector中
	pts.push_back(p1);
	pts.push_back(p2);
	pts.push_back(p3);
	pts.push_back(p4);
	pts.push_back(p5);

	fillPoly(canvas, pts, Scalar(100, 0, 255), LINE_AA, 0);
	polylines(canvas, pts, true, Scalar(0, 255, 0), 5, LINE_AA, 0);

	//创建保存多个多边形的容器
	std::vector<std::vector<Point>> contours;
	//将一组多边形压入容器
	contours.push_back(pts);
	drawContours(canvas, contours, 0, Scalar(0, 255, 200), 2);

	imshow("polycanvas", canvas);
}
